package cn.com.backstage.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.api.entity.ApiU_against;
import cn.com.api.entity.ApiU_circle;
import cn.com.api.entity.ApiU_circle_cate;
import cn.com.api.entity.ApiU_circle_post;
import cn.com.api.service.ApiU_circleService;
import cn.com.api.service.ApiU_circle_cateService;
import cn.com.backstage.controller.base.U_circleBaseController;

import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_BACKSTAGE + "/")
public class U_circleController extends U_circleBaseController {

	private static Logger logger = Logger.getLogger(U_circleController.class);

	@Autowired
	private ApiU_circleService apiU_circleService;
	@Autowired
	private ApiU_circle_cateService apiU_circle_cateService;

	/**
	 * 圈子列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "circlelist")
	public ModelAndView circlelist(HttpServletRequest request, HttpServletResponse response, PageInfo pageInfo)
			throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_circle_list.jsp");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		String circle_name = request.getParameter("circle_name");
		String create_name = request.getParameter("create_name");
		if (circle_name != null && !"".equals(circle_name)) {
			paramMap.put("circle_name", circle_name);
		}
		if (create_name != null && !"".equals(create_name)) {
			paramMap.put("create_name", create_name);
		}
		paramMap.put("followuser_id", 1);
		List<ApiU_circle> list = apiU_circleService.findCirclesListPage(paramMap, pageInfo);
		mv.addObject("list", list);
		mv.addObject("pageInfo", pageInfo);
		mv.addObject("paramMap", paramMap);
		return mv;
	}

	/**
	 * 圈子的举报信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "circleagainstlist")
	public ModelAndView circleagainstlist(HttpServletRequest request, HttpServletResponse response, PageInfo pageInfo)
			throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_circle_against_list.jsp");
		Map<String, Object> map = new HashMap<String, Object>();
		String circleid = request.getParameter("circleid");
		List<ApiU_against> list = apiU_circleService.getcircleagainstlist(circleid, pageInfo);
		mv.addObject("list", list);
		mv.addObject("pageInfo", pageInfo);
		mv.addObject("paramMap", map);
		return mv;
	}

	/**
	 * 圈子成员管理列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "circle_member_list")
	public ModelAndView circlememberlist(HttpServletRequest request, HttpServletResponse response, PageInfo pageInfo)
			throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_circle_member_list.jsp");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		String circle_name = request.getParameter("circle_name");
		String create_name = request.getParameter("create_name");
		if (circle_name != null && !"".equals(circle_name)) {
			paramMap.put("circle_name", circle_name);
		}
		if (create_name != null && !"".equals(create_name)) {
			paramMap.put("create_name", create_name);
		}
		paramMap.put("followuser_id", 1);
		List<ApiU_circle> list = apiU_circleService.findCirclesListPage(paramMap, pageInfo);
		mv.addObject("list", list);
		mv.addObject("pageInfo", pageInfo);
		mv.addObject("paramMap", paramMap);
		return mv;
	}

	/**
	 * 圈子分类列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "circlecatelist")
	public ModelAndView circlecatelist(HttpServletRequest request, HttpServletResponse response, PageInfo pageInfo)
			throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_circlecate_list.jsp");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("followuser_id", 1);
		List<ApiU_circle_cate> list = apiU_circle_cateService.findCircleCatesByMap(paramMap);
		mv.addObject("list", list);
		return mv;
	}

	/**
	 * 查看圈子详情信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "circleshow")
	public ModelAndView circleshow(HttpServletRequest request, HttpServletResponse response, PageInfo pageInfo)
			throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_circle_detail.jsp");
		String circleid = request.getParameter("circleid");
		ApiU_circle apiU_circle = apiU_circleService.findCircleInfo(Integer.valueOf(circleid));
		mv.addObject("circle", apiU_circle);
		return mv;
	}

}
